﻿using ConfigurationDemo;
using Microsoft.Extensions.Configuration;

IConfiguration Configuration = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
    .AddUserSecrets<Program>()
    .AddEnvironmentVariables()
    .AddCommandLine(args)
    .Build();

var connectionString = Configuration.GetSection("ConnectionStrings:Default").Value;
Console.WriteLine("Default: " + connectionString);

//Microsoft.Extensions.Configuration.Binder Package
var jwtOptions = new JwtOptions();
Configuration.GetSection(JwtOptions.Name).Bind(jwtOptions);
Console.WriteLine(jwtOptions.Audience);
Console.WriteLine(jwtOptions.Issuer);
Console.WriteLine(jwtOptions.ExpiresMinutes);
Console.WriteLine(jwtOptions.SymmetricSecurityKeyString);

var jwtOptions1 = Configuration.GetSection(JwtOptions.Name).Get<JwtOptions>();
Console.WriteLine(jwtOptions1.Audience);
Console.WriteLine(jwtOptions1.Issuer);
Console.WriteLine(jwtOptions1.ExpiresMinutes);
Console.WriteLine(jwtOptions1.SymmetricSecurityKeyString);